package poker;

import java.util.ArrayList;

import enums.ActionType;

public class ListUtils
{
	public static Card[] toArr(ArrayList<Card> list) {
		Card[] newHandArr = new Card[list.size()];
		for (int i = 0; i < newHandArr.length; i++) {
			newHandArr[i] = list.get(i);
		}
		
		return newHandArr;
	}
	
	public static boolean contains(ArrayList<Card> hand, int value) {
		for (int i = 0; i < hand.size(); i++) {
			if(hand.get(i).getValue() == value)
				return true;
		}
		return false;
	}
	
	public static boolean contains(ArrayList<ActionType> actions, ActionType actionType) {
		for (int i = 0; i < actions.size(); i++) {
			if(actions.get(i) == actionType)
				return true;
		}
		return false;
	}
	
	public static boolean contains(Card[] hand, Card card)
	{
		for (int i = 0; i < hand.length; i++) {
			if(hand[i] == null)
				System.out.println(i);
			if(hand[i].getValue() == card.getValue() && hand[i].getSuit() == card.getSuit())
				return true;
		}
		return false;
	}
	
	public static Card[] sortForPrefix(Card[] cards)
	{
		//Minste value f�rst
		Card[] sortedCards = new Card[2];
		int card1Value = cards[0].getValue();
		int card2Value = cards[1].getValue();
		
		if(card1Value < card2Value){
			sortedCards[0] = cards[0];
			sortedCards[1] = cards[1];
		}
		else{
			sortedCards[0] = cards[1];
			sortedCards[1] = cards[0];
		}
		
		return sortedCards;		
	}
}